refactor(ws): extract entryStillCurrent + tryWsClose helpers#143
Merged
Conversation
dedup 7 inline alive/current/viewer checks and 12 inline try/close/catch blocks in websocket.ts into two module-local helpers. behavior unchanged; log message strings preserved verbatim. phase 1 of plans/PLAN-lean-and-mean.md (v2). LOC delta is +23, not the predicted -40 to -60 \u2014 the original sites were already single-line, so the win is DRY + max-line-width drop (\~190 \u2192 \~120), not line count.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Dedup two patterns repeated throughout
src/server/websocket.ts:if (!entry.alive || activePtySessions.get(session) !== entry || entry.viewer !== ws) return;checks →entryStillCurrent(entry, session, ws)try { x.close(code, reason); } catch (e) { log.debug(..., { session, error: errMsg(e) }) }blocks →tryWsClose(target, code, reason, logMsg, session)Log message strings preserved verbatim. No behavior change.
verification
bun test tests/unit/— 1150 passbun test tests/integration/pty-takeover.test.ts tests/integration/concurrent-pty-viewer.test.ts tests/integration/take-control.test.ts— 48 pass (these are the integration tests that exercise every close path)notes
tryWsClosecovers only WebSocketclose(code, reason)sites;terminal.close()andproc.kill()stay inline since their signatures and error contexts differ.Phase 1 of
plans/PLAN-lean-and-mean.md(v2). Remaining phases (push tracker dedup, ralph log helper) were evaluated and skipped — shallow dedupe + sticky test API on the first, cosmetic rename on the second.